{include file="public/header"/}
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<style>
.layui-table-cell {height:30px!important;}
#organizationTreeBar{padding:10px 15px;border:1px solid #e6e6e6;background-color:#f2f2f2;}
#organizationTree{border:1px solid #e6e6e6;border-top:none;padding:10px 5px;overflow:auto;height:-webkit-calc(100vh - 125px);height:-moz-calc(100vh - 125px);height:calc(100vh - 125px);}
.layui-tree-entry .layui-tree-txt{padding:0 5px;border:1px transparent solid;text-decoration:none !important;}
.layui-tree-entry.ew-tree-click .layui-tree-txt{background-color:#fff3e0;border:1px #FFE6B0 solid;}
 #organizationUserTbSearchForm .layui-form-label{box-sizing:border-box !important;width:90px !important;}
#organizationUserTbSearchForm .layui-input-block{margin-left:90px !important;}
</style>
<div class="layui-fluid" style="padding-bottom:0;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-body" style="padding:10px;">
                    <div class="layui-form toolbar" id="organizationTreeBar">
                        栏目列表
                    </div>
                  <div id="organizationTree"></div>
                </div>
            </div>
        </div>
        <div class="layui-col-md9" id="LAY-component-layer-list">
            <div class="layui-card">
                <div class="layui-card-body" style="padding:10px;">
                    <div class="layui-form toolbar">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input name="keywords" id="keywords" class="layui-input" placeholder="标题搜索"/>
                                </div>
                            </div>
                            <input type="hidden" name="channel" id="channel" value="{$channel}">
                            <input type="hidden" name="typeid" id="typeid" value="{$typeid}">
                            <div class="layui-inline">
                                <button class="layui-btn icon-btn" lay-filter="formSubSearchUser" lay-submit>
                                    <i class="layui-icon">&#xe615;</i>搜索
                                </button>
                                {eq name='$channel' value='1'}
                                <button class="layui-btn icon-btn" id="pcfcms" data-type="Content_add" data-url="{:url('/Article/add')}">
                                <i class="layui-icon">&#xe654;</i>新增文档</button>
                                {else/}
                                <button class="layui-btn icon-btn" id="pcfcms" data-type="Content_add" data-url="{:url('/Custom/add')}">
                                <i class="layui-icon">&#xe654;</i>新增文档</button>
                                {/eq}
                            </div>
                        </div>
                    </div>
                    <table id="organizationUserTable" lay-filter="organizationUserTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="tableState">
<input type="checkbox" name="arcrank" data-id="{{d.aid}}" value="{{d.arcrank}}" lay-filter="arcrank" lay-skin="switch" lay-text="正常|锁定" {{d.arcrank == 0 ? 'checked':''}}>
</script>
<script type="text/html" id="tablebaidu">
<input type="checkbox" name="zzbaidu" data-id="{{d.aid}}" data-url="{{d.arcurl}}" value="{{d.zzbaidu}}" lay-filter="zzbaidu" lay-skin="switch" lay-text="已推送|未推送" {{d.zzbaidu == 1 ? 'checked':''}}>
</script>
<script type="text/html" id="userTbBar">
{{# if(d.channel == 1){ }}
<a class="layui-btn layui-btn-primary layui-btn-sm" data-type="Content_edit" data-url="{:url('/Article/edit')}" data-channel="{{d.channel}}" data-typeid="{{d.typeid}}" data-id="{{d.aid}}">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" data-type="Content_del" data-url="{:url('/Article/del')}"  data-id="{{d.aid}}" data-deltype="pseudo">删除</a>
{{# }else{ }}
<a class="layui-btn layui-btn-primary layui-btn-sm" data-type="Content_edit" data-url="{:url('/Custom/edit')}" data-channel="{{d.channel}}" data-typeid="{{d.typeid}}" data-id="{{d.aid}}">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" data-type="Content_del" data-url="{:url('/Custom/del')}" data-id="{{d.aid}}" data-deltype="pseudo">删除</a>
{{# } }}
<a class="layui-btn layui-btn-warm layui-btn-sm" href="{{d.arcurl}}" target="_blank">浏览</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'tree', 'dropdown', 'xmSelect', 'treeTable'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var tree = layui.tree;
        var xmSelect = layui.xmSelect;
        var selObj, treeData; 

        function renderTree() {
            $.post("{:url('/Content/leftmeun')}", function (res) {
                for (var i = 0; i < res.data.length; i++) {
                    res.data[i].title = res.data[i].organizationName;
                    res.data[i].id = res.data[i].organizationId;
                    res.data[i].spread = true;
                }
                treeData = layui.treeTable.pidToChildren(res.data, 'organizationId', 'parentId');
                tree.render({
                    elem: '#organizationTree',
                    onlyIconControl: true,
                    data: treeData,
                    click: function (obj) {
                        $("#LAY-component-layer-list #channel").val(obj.data.channelid);
                        $("#LAY-component-layer-list #typeid").val(obj.data.organizationId);
                        selObj = obj;
                        $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                        $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                        insTb2.reload({where:{typeid:obj.data.organizationId,channel:obj.data.channelid},page:{curr:1},url:"{:url('/Content/rightmeun')}"});
                    }
                });
                $('#organizationTree').find('.layui-tree-entry:first>.layui-tree-main>.layui-tree-txt').trigger('click');
            },"json");
        }
        renderTree();

        var insTb2 = table.render({
            elem: '#organizationUserTable',
            data: [],
            height: 'full-100',
            page: true,
            limit : 20,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                {field:'aid',title:'ID',width:60},
                {field: 'title', title: '标题',templet: function (d) {
                    if (d.is_b) {
                        var html = '<font style="font-weight:bold;">'+d.title+'</font>';
                    } else{
                        var html = '<font>'+d.title+'</font>';
                    }
                    if (d.is_head) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>头条</b>]</span>";
                    } 
                    if (d.is_recom) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>推荐</b>]</span>";
                    } 
                    if (d.is_special) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>特推</b>]</span>";
                    } 
                    if (d.is_litpic) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>图片</b>]</span>";
                    } 
                    if (d.is_jump) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>跳转</b>]</span>";
                    } 
                    return html;
                }},
                {field: 'typename',title: '所属栏目',align: 'center',templet: function (d) {
                    if(d.typename){
                       var html = "<font>"+d.typename+"</font>";
                    }else{
                       var html = "<font style='color:red;'>数据出错！</font>"; 
                    }
                    return html;
                }, width: 150},
                {field: 'status', templet: '#tableState', title: '状态',align: 'center',width: 100},
                {field: 'zzbaidu', templet: '#tablebaidu', title: '百度推送',align: 'center',width: 100},
                {field: 'click', title: '浏览量',align: 'center',width: 80},
                {field: 'update_time',title: '更新时间',align: 'center', width: 150},
                {title: '排序',align: 'center',templet: function (d) {
                    if(d.sort_order){
                       var html = "<input type='text' size='4' data-id='"+d.aid+"' value='"+d.sort_order+"' id='sort_order' class='layui-input' style='height:28px;'/>";
                    }else{
                       var html = ""+d.sort_order+""; 
                    }
                    return html;
                }, width: 80},
                {title: '操作',templet: '#userTbBar',align: 'center', width: 200},
            ]]
        });

        // 搜索
        form.on('submit(formSubSearchUser)', function (data) {
            insTb2.reload({typeid: data.field.typeid,channel: data.field.channel,keywords: data.field.keywords});
            return false;
        });

       //开启关闭
        form.on('switch(arcrank)', function(obj){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/index/changeTableVal")}';
            if (obj.elem.checked){
                $(this).val(0);
            }else{
                $(this).val(-1);
            }
            changeTableVal('archives','aid',dataid,'arcrank',this,pcfurl,'Content/index');
        });
        
        //百度推送
        form.on('switch(zzbaidu)', function(obj){
            var dataid = $(this).attr('data-id');
            var baiduurl = "{$Request.Domain}"+$(this).attr('data-url');
            var pcfurl = '{:url("/index/changeTableVal")}';
            if (obj.elem.checked){
                $(this).val(1);
                baiduTableVal(baiduurl,'{:url("/index/bdTableVal")}');
            }else{
                $(this).val(0);
            }
            changeTableVal('archives','aid',dataid,'zzbaidu',this,pcfurl,'Content/index');
        });
        
        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });  

        // 触发事件
        var active = {
            Content_add: function(){
                var obj = this;
                var channel = $("#LAY-component-layer-list #channel").val();
                var typeid =$("#LAY-component-layer-list #typeid").val();
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: $(this).attr('data-url')+"?pcfcms=0"+"&channel="+channel+"&typeid="+typeid
                });
            },
            Content_edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                var channel = $(obj).attr('data-channel');
                var typeid = $(obj).attr('data-typeid');
                var pcfcmsurl = $(obj).attr('data-url');
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: pcfcmsurl+"?pcfcms=0"+"&id="+id+"&channel="+channel+"&typeid="+typeid
                });
            },
            Content_del: function(){
                delfun(this);
            }
        };
        
        // 监听排序
        $(document).on("change","#LAY-component-layer-list #sort_order",function(){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/index/changeTableVal")}';
            changeTableVal('archives','aid',dataid,'sort_order',this,pcfurl);
        })

    });
</script>
</body>
</html>